package cn.itsource.pethome.org.controller;

import cn.itsource.pethome.basic.query.EmployeeQuery;
import cn.itsource.pethome.org.domain.Employee;
import cn.itsource.pethome.org.service.IEmployeeService;
import cn.itsource.pethome.basic.util.AjaxResult;
import cn.itsource.pethome.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private IEmployeeService service;

    @PutMapping
    public AjaxResult add(@RequestBody  Employee employee){
        try {
            service.addorupate(employee);
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false,e.getMessage());
        }
    }

    @PatchMapping("/loadAll")
    public List<Employee> findAll(){
        return  service.findEAll();
    }


    @DeleteMapping("{id}")
    public AjaxResult dele(@PathVariable("id") Long id ){
        try {
            service.delete(id);
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false,e.getMessage());
        }

    }
    @PatchMapping("/batchRemove")
    public AjaxResult batchRemove(@RequestBody  List<Employee> employees){
        try {
            service.batchRemove(employees);
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false,e.getMessage());
        }
    }
    /**
     * 查询全部，高级查询，分页
     * @param query
     * @return
     */
    @PatchMapping
    public PageList<Employee> loadAll(@RequestBody EmployeeQuery query){

       return service.loadEAll(query);
    }

}
